// https://leetcode.cn/problems/base-7/
// Created by ade on 2022/8/9.
//
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

class Solution {
public:
    // 官方方法
    string convertToBase71(int num) {
        char s[30];
        itoa(num, s, 7);
        string a = s;
        return a;
    }

    // 这种方式无法处理负数
    string convertToBase72(int num) {
        string s = "";
        while (num > 6) {
            s += num % 7 + '0';
            num = (num - num % 7) / 7;
        }
        s += num + '0';
        reverse(s.begin(), s.end());
        return s;
    }

    string convertToBase7(int num) {
        string s = "";
        int flag = 0;
        if(num < 0){
            flag = 1;
            num= -1 * num;
        }

        while (num > 6) {
            s += num % 7 + '0';
            num = (num - num % 7) / 7;
        }
        s += num + '0';
        reverse(s.begin(), s.end());
        if(flag) s = "-" + s;
        return s;
    }
};

int main() {
    Solution so;
    cout << so.convertToBase7(10);
    return 0;
}